home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / cppcom.zip / SERIALPO.HPP < prev    next >
C/C++ Source or Header  |  1991-05-25  |  3KB  |  101 lines

  1. /***************************************************************************
  2. These C++ classes are copyright 1990, by William Herrera.
  3.  
  4. All those who put this code or its derivatives in a commercial product MUST
  5. mention this copyright in their documentation for users of the products in
  6. which this code or its derivative classes are used.  Otherwise, this code
  7. may be freely distributed and freely used for any purpose.
  8.  
  9. Enhancements: 1991 by David Orme
  10.     *  General cleanup.
  11.             - I/O now takes advantage of C++ overloading.
  12.             - Serial port I/O functionality now only in Serial class.
  13.             - Modem functionality now only in Modem class.
  14.     *  Possible to easily implement file Xfr prots now.
  15.     *  CCITT CRC-16 class added                            -- 2-20-1991
  16.     *  BIOS Timer class added                                -- 2-22-1991
  17.     *  Optional timeout on all input routines added    -- 2-25-1991
  18.  
  19. ***************************************************************************/
  20.  
  21. // file serialpo.hpp class declaration of SerialPort class.
  22.  
  23. #ifndef SERIALPO_HPP
  24. #define SERIALPO_HPP 1
  25.  
  26. #include <string.h>
  27. #include "comports.hpp"
  28. #include "timer.h"
  29.  
  30. class SerialPort
  31. {
  32. protected:
  33. // the protected data within each Serial object
  34.  
  35.     int port_number;
  36.     boolean translatenewline;    // These are used in '\r\n' <--> '\n'
  37.     boolean lastin_wascr;        // translation.
  38.     uart * com;                    // pointer to the uart for port
  39.     Timer T;                    // Async timer
  40.  
  41. public:
  42.     SerialPort(int portnum = 1, int speed = 2400, 
  43.                     parity_t p = NOPAR, int sbits = 1, 
  44.                     int dbits = 8, boolean trans = false);
  45.     virtual ~SerialPort();
  46.     uart * GetUART();
  47.     void SetSpeed(int s);
  48.     int GetSpeed();
  49.     void SetParity(parity_t p);
  50.     parity_t GetParity();
  51.     void SetStopBits(int s);
  52.     int GetStopBits();
  53.     void SetDataBits(int s);
  54.     int GetDataBits();
  55.     void PurgeInput();
  56.     void FlushOutput();
  57.     void PurgeOutput();
  58.     boolean CarrierPresent();
  59.     void RaiseDTR();
  60.     void DropDTR();
  61.     void SetTimer(float seconds = 0.0e1) { T.Set(seconds); }
  62.     int TimeOut()                    { return T.TimeOut(); }
  63.     void Pause(int ms = 550);
  64.     void Break(int ms = 550);
  65.     void SetDoIfNoCarrier(void (*f)());
  66.     void SetDoOnRing(void (*f)());
  67.     boolean InputEmpty();
  68.     boolean OutputEmpty();
  69.     boolean OutputReady();
  70.  
  71.     // Binary write (no /r/n xlation)
  72.     void Write(void * p,int n);
  73.  
  74.     void Write(char c)        { Write(&c, sizeof(char)); }
  75.     void Write(char *s)         { Write(s, strlen(s)); }
  76.     void Write(int i)        { Write(&i, sizeof(int)); }
  77.     void Write(unsigned i)            { Write(&i, sizeof(unsigned)); }
  78.     void Write(long l)        { Write(&l, sizeof(long)); }
  79.     void Write(float f)        { Write(&f, sizeof(float)); }
  80.     void Write(double d)        { Write(&d, sizeof(double)); }
  81.  
  82.     // Binary read with timeout in s seconds
  83.     int Read(char * p, int n, float secs = 0.0e1);
  84.  
  85.     int Read(char & c, float s = 0.0e1)  { return Read((char*)&c, sizeof(char), s); }
  86.     int Read(int& i, float s = 0.0e1)    { return Read((char*)&i, sizeof(int), s); }
  87.     int Read(unsigned& i,float s = 0.0e1){ return Read((char*)&i, sizeof(unsigned), s); }
  88.     int Read(long& l, float s = 0.0e1)   { return Read((char*)&l, sizeof(long), s); }
  89.     int Read(float& f, float s = 0.0e1)  { return Read((char*)&f, sizeof(float), s); }
  90.     int Read(double& d, float s = 0.0e1) { return Read((char*)&d, sizeof(double), s); }
  91.  
  92.     // Translated I/O (if /r/n xlation enabled)
  93.     int Receive(char& ch, float secs = 0.0e1); // -1 returned on timeout
  94.     void Send(char ch);
  95.     void Send(char * s);
  96. };
  97.  
  98. #endif
  99.  
  100. // end of file serialpo.hpp
  101.